package com.lzx.iteam.util;

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class SkinUtil {
    
    public static final int SKIN_V_T9 = 1;
    public static final int SKIN_V_QWERTY = 2;
    public static final int SKIN_H_T9 = 3;
    public int mSkinType = SKIN_V_T9;
    
    /**
     * 解析xml
     * @param arrElement
     * @return
     */
    public static int parseColorProperty(Element arrElement){
        if(arrElement==null){
            return 0;
        }
        NodeList rgb = arrElement.getElementsByTagName("integer");
        String r = rgb.item(0).getFirstChild().getNodeValue();
        String g = rgb.item(1).getFirstChild().getNodeValue();
        String b = rgb.item(2).getFirstChild().getNodeValue();
        int color = Color.rgb(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b));
        return color;
    }
    
    public static String filter(String xmlStr) {  
        StringBuilder sb = new StringBuilder();  
        char[] chs = xmlStr.toCharArray();  
        for(char ch : chs) {  
            if((ch >= 0x00&&ch <= 0x08)  
                || (ch >= 0x0b&& ch <= 0x0c)  
                || (ch >= 0x0e&& ch <= 0x1f)) {  
            } else {  
                sb.append(ch);  
            }  
        }  
        return sb.toString();  
    }  
    

    public static StateListDrawable setbg(int[] stateList,Resources res) {
        StateListDrawable bg = new StateListDrawable();
        Drawable normal = res.getDrawable(stateList[0]);
//        Drawable selected = res.getDrawable(stateList[1]);
        Drawable pressed = res.getDrawable(stateList[2]);
//        bg.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, selected);  
//        bg.addState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled}, pressed);  
//        bg.addState(new int[]{android.R.attr.state_focused}, selected);  
        bg.addState(new int[]{android.R.attr.state_pressed}, pressed);  
//        bg.addState(new int[]{android.R.attr.state_enabled}, normal);  
        bg.addState(new int[]{}, normal);  
        return bg;
}
    
    public static StateListDrawable setbg(int[] stateList,Resources newres,Resources res) {
        StateListDrawable bg = new StateListDrawable();
        Drawable normal = newres.getDrawable(stateList[0]);
        Drawable pressed = res.getDrawable(stateList[2]);
        bg.addState(new int[]{android.R.attr.state_pressed}, pressed);
        bg.addState(new int[]{}, normal);
        return bg;
    }
}
